<template>
	<card shadw>
	    <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="130">
	        <FormItem label="考场名称" prop="name">
	        	<Row>
	                <Col span="11">
	            		<Input v-model="formValidate.name" placeholder="请输入考场名称"></Input>
	            	</Col>
	            </Row>
	        </FormItem>
	        <FormItem label="绑定考试试卷" prop="city">
	        	<Row>
	                <Col span="11">
			            <Select v-model="formValidate.city" placeholder="请选择绑定试卷">
			                <Option v-for="v in data1" :value="v.Id" :key="v.Id">{{v.name}}</Option>
			            </Select>
			   		</Col>
	            </Row>        
	        </FormItem>
	        <FormItem label="考试时段" prop="date1">
	            <Row>
	                <Col span="11">
	                    <DatePicker id="time1" type="datetimerange" split-panels placeholder="请选择时间" v-model="formValidate.date1"></DatePicker>
	                </Col>
	            </Row>
	        </FormItem>
	        <FormItem label="交卷后是否显示分数" prop="gender">
	            <RadioGroup v-model="formValidate.gender">
	                <Radio label="1">显示</Radio>
	                <Radio label="0">不显示</Radio>
	            </RadioGroup>
	        </FormItem>
	        <FormItem label="交卷后是否归档" prop="gender1">
	            <RadioGroup v-model="formValidate.gender1">
	                <Radio label="1">直接归档</Radio>
	                <Radio label="0">手动归档</Radio>
	            </RadioGroup>
	        </FormItem>
	        <FormItem label="是否启用" prop="gender2">
	            <RadioGroup v-model="formValidate.gender2">
	                <Radio label="1">启用</Radio>
	                <Radio label="0">关闭</Radio>
	            </RadioGroup>
	        </FormItem>
	        <FormItem>
	            <Button type="primary" @click="handleSubmit('formValidate')">保存</Button>
	              <Modal
			        v-model="modal1"
			        @on-ok="ok"
			        @on-cancel="cancel">
			        <p>考场添加完成，是否立即前往【考场配置-考生管理】，导入考生信息。</p>
			    </Modal>
	            <Button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">取消</Button>
	        </FormItem>
	    </Form>
	</card>   
</template>
<script>
import util from "@/libs/util.js";
    export default {
        data () {
            return {
                formValidate: {
                    name: '',
                    city: '',
                    gender: '',
                    gender1:"",
                    date1: '',
                    gender2: ''
                },
                data1:"",
                modal1: false,
                testPaperId:"",
                examinationRoomId1:0,
                ruleValidate: {
                    name: [
                        { required: true, message: '请输入名称', trigger: 'blur' }
                    ],
                    city: [
                        { required: true, message: '请绑定试卷', trigger: 'change' }
                    ],
                    gender: [
                        { required: true, message: '请选择是否显示分数', trigger: 'change' }
                    ],
                    gender1: [
                        { required: true, message: '请选择是否归档', trigger: 'change' }
                    ],
                    date1: [
                        { required: true, message: '请选择时间', trigger: 'change',type: 'array'}
                    ],
                    gender2: [
                        { required: true, message: '是否启用', trigger: 'change' }
                    ],
                }
            }
        },
        watch:{
        	
        },
//      获取试卷信息
        created:function(){
	    	var that=this;
	    	that.axios({
				method:"get",
				url:that.$store.state.app.globalUrl+"/admin/TestPaper/index?size=9999",
				data:{
					
				}
			}).then(function(res){
				that.data1=res.data.data.list
				that.data1.forEach(function(v,i){
					that.data1[i].Id=that.data1[i].Id+"";
				})
			})
    	},
        methods: {
//      	保存
            handleSubmit (name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                      	var that=this;
                      	console.log(that.formValidate.date1[0])
			    		this.axios({
			    			method:'post',
			    			url:that.$store.state.app.globalUrl+'/admin/ExaminationRoom/add',
			    			data:{
			    				name:that.formValidate.name,
			    				testPaperId:that.formValidate.city,
			    				isShowScore:that.formValidate.gender==1?1:0,
			    				isPigeonhole:that.formValidate.gender1==1?1:0,
			    				examStartTime:Date.parse(new Date(that.formValidate.date1[0])) / 1000,
			    				examEndTime:Date.parse(new Date(that.formValidate.date1[1])) / 1000,
			    				status:that.formValidate.gender2==1?1:0,
			    			}
			    		}).then(function(res){
			    			that.examinationRoomId1=res.data.data.examinationRoomId;
			    			if(res.data.msg=='操作成功'){
			    				that.modal1=true
				 			}else{
				     			that.$Message.error('修改失败');
				 			}
			    		})
                    } else {
                        this.$Message.error('请填写完整');
                    }
               })
            },
//          取消
            handleReset (name) {
                this.$refs[name].resetFields();
                 this.$router.push({
					name:'examination-set'	
				})
            },
//          模态框点确定执行
            ok () {
                this.$Message.info('确认');
                this.$router.push({
					name:'examinee-management',
					query:{id:this.examinationRoomId1}
				})
            },
//          模态框点取消执行
            cancel () {
                this.$Message.info('取消');
                this.$router.push({
					name:'examination-set'	
				})
            }
        }
    }
</script>
<style scoped>
#time1{width: 280px !important;}
</style>